GetWindowsVersionEx

Prototype:

procedure GetWindowsVersionEx(var Version: TWindowsVersion);

Description:

Returns extended information about the version of Windows in a record.

TWindowsVersion is defined as:

  TWindowsVersion = record
    Major: Cardinal;             // Major version number
    Minor: Cardinal;             // Minor version number
    Build: Cardinal;             // Build number
    ServicePackMajor: Cardinal;  // Major version number of service pack
    ServicePackMinor: Cardinal;  // Minor version number of service pack
    NTPlatform: Boolean;         // True if an NT-based platform
    ProductType: Byte;           // Product type (see below)
    SuiteMask: Word;             // Product suites installed (see below)
  end;

The ProductType field can be one of the following values:

  VER_NT_WORKSTATION
  VER_NT_DOMAIN_CONTROLLER
  VER_NT_SERVER

It can also be zero if the user is running Windows 95/98/Me, or if the product type could not be determined (unlikely). VER_NT_WORKSTATION indicates a non-server edition of Windows (e.g. Workstation, Professional, or Home).

The SuiteMask field can be a combination of the following values:

  VER_SUITE_BACKOFFICE
  VER_SUITE_BLADE
  VER_SUITE_DATACENTER
  VER_SUITE_ENTERPRISE
  VER_SUITE_EMBEDDEDNT
  VER_SUITE_PERSONAL
  VER_SUITE_SINGLEUSERTS
  VER_SUITE_SMALLBUSINESS
  VER_SUITE_SMALLBUSINESS_RESTRICTED
  VER_SUITE_TERMINAL

VER_SUITE_PERSONAL, for example, is set on Home edition of Windows XP, and VER_SUITE_BLADE is set on the Web edition of Windows Server 2003. On Windows 95/98/Me and NT 4.0, SuiteMask is always zero.

Example:

The following example demonstrates how you can disallow installation on certain editions of Windows, and check service pack levels on multiple operating system versions. (Neither of these things are possible with the MinVersion [Setup] section directive.)

function InitializeSetup: Boolean;
var
  Version: TWindowsVersion;
  S: String;
begin
  GetWindowsVersionEx(Version);

  // Disallow installation on Home edition of Windows
  if Version.SuiteMask and VER_SUITE_PERSONAL <> 0 then
  begin
    SuppressibleMsgBox('This program cannot be installed on a Home edition of Windows.',
      mbCriticalError, MB_OK, MB_OK);
    Result := False;
    Exit;
  end;

  // Disallow installation on domain controllers
  if Version.ProductType = VER_NT_DOMAIN_CONTROLLER then
  begin
    SuppressibleMsgBox('This program cannot be installed on domain controllers.',
      mbCriticalError, MB_OK, MB_OK);
    Result := False;
    Exit;
  end;

  // On Windows 2000, check for SP4
  if Version.NTPlatform and
     (Version.Major = 5) and
     (Version.Minor = 0) and
     (Version.ServicePackMajor < 4) then
  begin
    SuppressibleMsgBox('When running on Windows 2000, Service Pack 4 is required.',
      mbCriticalError, MB_OK, MB_OK);
    Result := False;
    Exit;
  end;

  // On Windows XP, check for SP2
  if Version.NTPlatform and
     (Version.Major = 5) and
     (Version.Minor = 1) and
     (Version.ServicePackMajor < 2) then
  begin
    SuppressibleMsgBox('When running on Windows XP, Service Pack 2 is required.',
      mbCriticalError, MB_OK, MB_OK);
    Result := False;
    Exit;
  end;

  Result := True;
end;